﻿Imports DevExpress.Web
Imports System.Data.SqlClient

Public Class AdminUpdateUser
    Inherits System.Web.UI.Page
    Dim p As New DocGia_DTO()
    Dim docgia As New DocGia_BLL()
    Dim gioitinh As String
    Dim hinh As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        load_DocGia()
        If Not IsPostBack Then
            Session("hinhdocgiamoi") = String.Empty
        End If
    End Sub
    Public Sub load_DocGia()
        cardview_docgia.DataSource = docgia.load_DocGia()
        cardview_docgia.DataBind()
    End Sub

    Protected Sub cardview_docgia_CardUpdating(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataUpdatingEventArgs) Handles cardview_docgia.CardUpdating
        p._taikhoan = e.Keys("taikhoan")
        p._hoten = e.NewValues("ten")
        If e.NewValues("ghichu") = String.Empty Then
            p._ghichu = e.OldValues("ghichu")
        Else
            p._ghichu = e.NewValues("ghichu")
        End If
        p._sodienthoai = e.NewValues("sdt")
        p._diachi = e.NewValues("diachi")
        p._gioitinh = e.NewValues("gioitinh")
        If String.IsNullOrEmpty(Session("hinhdocgiamoi").ToString()) Then
            p._hinh = Session("hinhdocgiacu").ToString()
            Session("hinhdocgiacu") = String.Empty
        Else
            p._hinh = "\img\user\" + Session("hinhdocgiamoi").ToString()
            Session("hinhdocgiamoi") = String.Empty
        End If
        docgia.CapNhap_Docgia(p)
        cardview_docgia.CancelEdit()
        e.Cancel = True
        load_DocGia()
    End Sub
    Protected Sub upload_hinh_FileUploadComplete(ByVal sender As Object, ByVal e As DevExpress.Web.FileUploadCompleteEventArgs)
        Dim filename As String = e.UploadedFile.FileName
        e.UploadedFile.SaveAs(MapPath("~/img/user/") + filename)
        e.CallbackData = filename
        Session("hinhdocgiamoi") = filename
    End Sub
    Protected Sub cardview_docgia_CellEditorInitialize(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxCardViewEditorEventArgs) Handles cardview_docgia.CellEditorInitialize
        hinh = cardview_docgia.GetCardValues(e.VisibleIndex, "hinh")
        Session("hinhdocgiacu") = hinh
    End Sub



    Protected Sub cardview_docgia_CardDeleting(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataDeletingEventArgs) Handles cardview_docgia.CardDeleting
        Try
            p.taikhoan = e.Keys("taikhoan")
            docgia.xoaDocGia(p)
            e.Cancel = True
            load_DocGia()
        Catch ex As SqlException
            cardview_docgia.JSProperties("cp_showAlertMessage") = ex.Message
            e.Cancel = True
        End Try

    End Sub

End Class